package team;


import gnu.io.SerialPortEvent;

import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
 
      
class test_Frame extends JFrame implements ActionListener{
        JButton jbt = new JButton("나비야");
        JButton jbt2 = new JButton("비행기");
        test_Frame2 tf2;
        test_Frame3 tf3;

    	public test_Frame(){
    			super("노래선택");		//노래 선택창 이름 선언
                this.setLayout(new GridLayout(0,2));
                getContentPane().add(jbt);
                getContentPane().add(jbt2);
               
                this.setSize(1000,800);
                this.setVisible(true);
               
                jbt.addActionListener(this);
                jbt2.addActionListener(this);
        }
 
        @Override
        public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
        		if(arg0.getSource() == jbt){
        			tf2 = new test_Frame2(arg0.getActionCommand());
        		}else if( arg0.getSource() == jbt2){
        			tf3 = new test_Frame3(arg0.getActionCommand());
        		}
        }
}
 
class test_Frame2 extends JDialog{
    JScrollPane scrollPane;
    ImageIcon icon, icon2, icon5, icon6;
    int nextKey = 0;
        JLabel jlb = new JLabel("");
        public test_Frame2(String str){
        	
                getContentPane().add(jlb);
                jlb.setText(str.toString());
                icon = new ImageIcon("C:\\Users\\kkkkk\\workspace\\team\\butterfly.jpg");
                icon2 = new ImageIcon("C:\\Users\\kkkkk\\workspace\\team\\keyboard.jpg");  
                icon5 = new ImageIcon("C:\\Users\\kkkkk\\workspace\\team\\pointer.jpg");
                icon6 = new ImageIcon("C:\\Users\\kkkkk\\workspace\\team\\removeKey.jpg");
                JPanel background = new JPanel() {
                   

                	public void paintComponent(Graphics g) {
                    	int a = 54;
                    	int song[] = {5,3,3,4,2,2};
                    	int ii;
                        g.drawImage(icon.getImage(), 200, 100, null);
                        g.drawImage(icon2.getImage(), 250, 600, null);                                               
                        setOpaque(false); //그림을 표시하게 설정,투명하게 조절
                        super.paintComponent(g);
                    }        	
                	public void nextDraw(int nextKey, Graphics g){		//다음 입력할 키
                		boolean bool;
                		bool = g.drawImage(icon5.getImage(), 255 + ((nextKey -1) * 35), 720, null);
                	}
                	public void removeDraw(int nextKey, Graphics g){		//키를 눌렀을 시 지우는 키
                		boolean bool;
                		bool = g.drawImage(icon6.getImage(), 255 + ((nextKey -1) * 35), 720, null);
                	}
                	

                };
                JFrame object = new JFrame(){
                	int a = 54;
                	int song[] = {5,3,3,4,2,2};
                	int ii;
                };
                	
                
                
                JLabel Label = new JLabel("피아노 교습 프로그램\r\n");
                background.add(Label);
                scrollPane = new JScrollPane(background);
                setContentPane(scrollPane);
                
                this.setSize(1000,800);
                this.setModal(true);
                this.setVisible(true);
               
        }
}
class test_Frame3 extends JDialog{
    JScrollPane scrollPane;
    ImageIcon icon3, icon2, icon4, icon6;
    int nextKey = 0;
    JLabel jlb = new JLabel("");
    public test_Frame3(String str){
            getContentPane().add(jlb);
           
            jlb.setText(str.toString());
            icon3 = new ImageIcon("C:\\Users\\kkkkk\\workspace\\team\\plane.jpg");
            icon2 = new ImageIcon("C:\\Users\\kkkkk\\workspace\\team\\keyboard.jpg");   
            icon4 = new ImageIcon("C:\\Users\\kkkkk\\workspace\\team\\pointer3.jpg");
            icon6 = new ImageIcon("C:\\Users\\kkkkk\\workspace\\team\\removeKey.jpg");
            JPanel background = new JPanel() {
                public void paintComponent(Graphics g) {
                    g.drawImage(icon3.getImage(), 200, 100, null);
                    g.drawImage(icon2.getImage(), 250, 600, null);
                    setOpaque(false); //그림을 표시하게 설정,투명하게 조절
                    super.paintComponent(g);
                }
            	public void nextDraw(int nextKey, Graphics g){
            		boolean bool;
            		bool = g.drawImage(icon4.getImage(), 255 + ((nextKey -1) * 35), 720, null);
            	}
            	public void removeDraw(int nextKey, Graphics g){		//키를 눌렀을 시 지우는 키
            		boolean bool;
            		bool = g.drawImage(icon6.getImage(), 255 + ((nextKey -1) * 35), 720, null);
            	}
            	
            };
            JPanel objects = new JPanel() {
                public void paintComponent(Graphics g) {

                     
                	try {
						Thread.sleep(2000);
	                    nextKey = 4;
	                    nextDraw(nextKey, g);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
                    setOpaque(false); //그림을 표시하게 설정,투명하게 조절
                    super.paintComponent(g);
                }
            	public void nextDraw(int nextKey, Graphics g){
            		boolean bool;
            		bool = g.drawImage(icon4.getImage(), 255 + ((nextKey -1) * 35), 720, null);
            	}
            	public void removeDraw(int nextKey, Graphics g){		//키를 눌렀을 시 지우는 키
            		boolean bool;
            		bool = g.drawImage(icon6.getImage(), 255 + ((nextKey -1) * 35), 720, null);
            	}
            };
            JLabel Label = new JLabel("피아노 교습 프로그램\r\n");
            background.add(Label);
            scrollPane = new JScrollPane(background);
            setContentPane(scrollPane);
           
            this.setSize(1000,800);
            this.setModal(true);
            this.setVisible(true);
           
    }
}

public class test {
    public static void main (String [] args) {
    		String song[] ={ "So", "Mi", "Mi","Fa","Re","Re"};
            test_Frame tf = new test_Frame();
            SerialTest main = new SerialTest();
            
            for (int i = 0; i < 4; i++){
            	System.out.println(song[i]);
            	if(true){
                    main.initialize(); 
                    System.out.println("\n");
            	}
            }
        //    main.initialize();  
            
    }
}



             
